<?php
/* @var $this DefaultController */
/* @var $model FormModel */

$this->pageTitle = Yii::app()->name . ' - ' . $model->name;
//Util::tsRegisterAssetJs('_submit_modal.js');
Util::tsRegisterAssetJs('submit.js');
Yii::app()->clientScript->registerCssFile($this->module->assetsUrl . '/css/nosey-form-modal.css');
?>

<h1 class="name-title span12"><i class="icon-file-text"></i> <?php echo $model->name ?></h1>

<p><?php echo $model->description ?></p>

<?php
$form = $this->beginWidget('ext.AweCrud.components.AweActiveForm', array(
    'id' => 'submit-form',
    'enableAjaxValidation' => true,
    'clientOptions' => array('validateOnSubmit' => true, 'validateOnChange' => false,),
    'enableClientValidation' => false,
        ));
?>
<div class="row-fluid">
    <p class="note"><?php echo Yii::t('noseyModule.app', 'Fields with') ?> <span class="required">*</span> <?php echo Yii::t('noseyModule.app', 'are required') ?>.</p>

    <?php // echo $form->errorSummary($form_model) ?>
    <?php echo $form->hiddenField($model, 'id') ?>


    <?php foreach ($model->sections as $section): ?>
        <div class="widget blue"> 
            <div class="widget-title">
                <h4><?php echo $section->name ?></h4>
                <span class="tools">
                    <a href="javascript:;" class="icon-chevron-down"></a>
                    <!--a href="javascript:;" class="icon-remove"></a-->
                </span>
            </div>
            <div class="widget-body">
                <div class="nsy_form_section">

                                            <!--<div class="nsy_form_section_header"><h3><?php // echo $section->name                    ?></h3></div>-->
                    <div class="nsy_form_section_content">

                        <?php foreach ($section->fields as $field): ?>
                            <div class="control-group">
                                <?php
                                switch ($field->field_type) {
                                    case Field::FIELD_TYPE_TEXT:
                                        ?>
                                        <div class="controls">
                                            <?php
                                            if ($field->widget_type == Field::WIDGET_TYPE_TEXT) {
                                                echo $form->textFieldRow($form_model, $field->id, array('class' => ' nsy_element_input'));
                                            } elseif ($field->widget_type == Field::WIDGET_TYPE_TEXTAREA) {
                                                echo $form->textAreaRow($form_model, $field->id, array('class' => 'nsy_element_input'));
                                            }
                                            ?>
                                        </div>
                                        <?php
                                        break;
                                    case Field::FIELD_TYPE_SIMPLE:
                                        ?>
                                        <div class="controls">
                                            <?php
                                            if ($field->widget_type == Field::WIDGET_TYPE_RADIO) {
                                                echo $form->radioButtonListRow($form_model, $field->id, CHtml::listData($field->options, 'id', 'label'), array('class' => 'nsy_element_check'));
                                            } elseif ($field->widget_type == Field::WIDGET_TYPE_SELECT) {
                                                echo $form->dropDownListRow($form_model, $field->id, CHtml::listData($field->options, 'id', 'label'), array('empty' => Yii::t('noseyModule.app', '- Select one -'), 'class' => 'nsy_element_select'));
                                            }
                                            ?>
                                        </div>
                                        <?php
                                        break;
                                    case Field::FIELD_TYPE_MULTIPLE:
                                        ?>
                                        <div class="controls">
                                            <?php
                                            if ($field->widget_type == Field::WIDGET_TYPE_CHECKBOX) {
                                                echo $form->checkBoxListRow($form_model, $field->id, CHtml::listData($field->options, 'id', 'label'), array('multiple' => true, 'class' => 'nsy_element_check'));
                                            } elseif ($field->widget_type == Field::WIDGET_TYPE_SELECT) {
                                                echo $form->dropDownListRow($form_model, $field->id, CHtml::listData($field->options, 'id', 'label'), array('multiple' => true, 'class' => 'nsy_element_check'));
                                            }
                                            ?>
                                        </div>
                                        <?php
                                        break;
                                    case Field::FIELD_TYPE_BOOLEAN:
                                        echo $form->labelEx($form_model, $field->id);
                                        $this->widget(
                                                'bootstrap.widgets.TbToggleButton', array(
                                            'model' => $form_model,
                                            'disabledLabel' => 'NO',
                                            'enabledLabel' => 'SI',
                                            'width' => 100,
                                            'attribute' => "$field->id",
                                            'onChange' => 'js:function($el, status, e){console.log($el, status, e);}'
                                                )
                                        );
                                        echo '<span class="help-inline error" id="DynamicFormModel_' . $field->id . '_em_" style=""></span>';
//                    echo $form->checkBoxRow($form_model,$field->id);
                                        break;
                                    case Field::FIELD_TYPE_DATE:
                                        ?>
                                        <div class="controls">
                                            <?php
                                            echo $form->datepickerRow($form_model, $field->id, array('options' => array('autoclose' => true), 'class' => 'nsy_element_date'));
                                            ?>
                                        </div>
                                        <?php
                                        break;
                                    case Field::WIDGET_TYPE_STAR_RATING:
                                        ?>
                                        <div class="controls">
                                            <?php
                                            if ($field->widget_type == Field::WIDGET_TYPE_STAR_RATING) {
                                                echo $form->labelEx($form_model, $field->id);
                                                $this->widget('CStarRating', array(
                                                    'name' => "DynamicFormModel[$field->id]",
                                                    'value' => '0',
                                                    'allowEmpty' => false,
                                                    'minRating' => 1,
                                                    'maxRating' => $field->options[0]->label,
                                                    'starCount' => $field->options[0]->label,
                                                ));
                                                echo '<span class="help-inline error" id="DynamicFormModel_' . $field->id . '_em_" style=""></span>';
                                            } elseif ($field->widget_type == Field::WIDGET_TYPE_SELECT) {
                                                $valoresData = array();
                                                for ($i = 0; $i <= $field->options[0]->label; $i++) {
                                                    $valoresData[$i] = $i;
                                                }
                                                echo $form->select2Row($form_model, $field->id, array(
                                                    'asDropDownList' => true,
//                                                    'empty' => '- Ninguna -',
//                                                   'empty' =>array(0=> '- Ninguna -'),
                                                    'data' => $valoresData,
//                                                    'class' => 'span6',
                                                ));
                                            }
                                            ?>
                                        </div>
                                        <?php
                                        break;
                                    default: break;
                                }
                                ?>
                            </div>
                        <?php endforeach; ?>
                    </div>
                </div>
            </div>
        </div>
    <?php endforeach; ?>

    <div class="nsy_buttons control-group center">
        <?php
        $this->widget('bootstrap.widgets.TbButton', array(
//            'buttonType' => 'submit',
            'type' => 'primary',
            'label' => Yii::t('noseyModule.app', 'Save'),
            'htmlOptions' => array(
                'onClick' => 'js:llenarEncuesta("#submit-form")')
        ));
        ?>
    </div>
    <?php $this->endWidget(); ?>

</div>